package com.mk.web.io.file.threadpool;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.mk.web.io.file.client.nio.NioClient;

/**
 * 自定义线程组
 * Created by WangChen on 2018/12/15 15:42.
 */
public class UserThreadFactory implements ThreadFactory{

    private final String namePrefix;
    private final AtomicInteger nextId = new AtomicInteger(1);

    public UserThreadFactory(String featureOfGroup){
        namePrefix = "UserThreadFactory`s " + featureOfGroup + "-Worker-";
    }
    @Override
    public Thread newThread(Runnable task) {
        String name = namePrefix + nextId.getAndIncrement();
        Thread thread = new Thread(null, task, name, 0);
        System.out.println(thread.getName());
        return thread;
    }
}

